<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>图书管理系统</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.2.3/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container {
            margin-top: 30px;
        }
        .search-form {
            margin-bottom: 20px;
        }
        .alert {
            margin-bottom: 20px;
        }
        .no-results {
            text-align: center;
            padding: 50px;
            color: #666;
        }
        .input-group .btn {
            margin-left: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2 class="text-center mb-4">图书管理系统</h2>
        
        <!-- 搜索表单 -->
        <form class="search-form" action="${pageContext.request.contextPath}/books/search" method="get">
            <div class="input-group">
                <input type="text" class="form-control" name="keyword" placeholder="输入书名或作者进行搜索">
                <button type="submit" class="btn btn-primary">搜索</button>
                <button type="button" class="btn btn-secondary" onclick="location.href='${pageContext.request.contextPath}/books/list2'">显示全部</button>
            </div>
        </form>

        <!-- 在搜索表单下方添加搜索结果提示 -->
        <c:if test="${not empty keyword}">
            <div class="alert alert-info">
                搜索"${keyword}"的结果：
            </div>
        </c:if>

        <!-- 修改表格部分，添加空状态处理 -->
        <c:choose>
            <c:when test="${not empty books}">
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>书名</th>
                            <th>作者</th>
                            <th>出版社</th>
                            <th>ISBN</th>
                            <th>价格</th>
                            <th>库存</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${books}" var="book">
                            <tr>
                                <td>${book.id}</td>
                                <td>${book.name}</td>
                                <td>${book.author}</td>
                                <td>${book.publisher}</td>
                                <td>${book.isbn}</td>
                                <td>￥${book.price}</td>
                                <td>${book.stock}</td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
            </c:when>
            <c:otherwise>
                <c:if test="${empty keyword}">
                    <div class="alert alert-info">
                        当前没有书籍信息
                    </div>
                </c:if>
                <c:if test="${not empty keyword}">
                    <div class="alert alert-warning">
                        未找到相关书籍
                    </div>
                </c:if>
            </c:otherwise>
        </c:choose>
    </div>
</body>
</html>
